package com.zhangshuo.patternDesign.obverser.eventDrivern;

import java.util.Vector;

/**
 * Created by shuo.zhang on 2017-10-22.
 */
public class Button {

    private Vector<ButtonListener> listeners = new Vector<>();

    private Integer id;
    private String name;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Button(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public boolean addListener(ButtonListener listener) {
        return listeners.add(listener);
    }

    public boolean delListener(ButtonListener listener) {
        return listeners.remove(listener);
    }

    public void click() {
        System.out.println(this.name + " 被点击");
        ButtonEvent event = new ButtonEvent(this);
        for (ButtonListener listener : listeners) {
            listener.onClick(event);
        }
    }

    public void doubleClick() {
        System.out.println(this.name +" 被双击");
        ButtonEvent event = new ButtonEvent(this);
        for (ButtonListener listener : listeners) {
            listener.onDoubleClick(event);
        }
    }


}
